package phi.game.ball.layers
{
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	
	import flash.geom.Point;
	
	import phi.engine.actors.ActorOptions;
	import phi.engine.actors.IInteractiveActor;
	import phi.engine.layers.HScrollLayer;
	import phi.engine.utils.PhiMathUtil;
	
	public class BlocksScrollLayer extends HScrollLayer
	{
		public var topPadding :Number = 0;
		
		public function BlocksScrollLayer()
		{
			super();
		}
		
		override protected function createActorOptions(startPosition:Point):ActorOptions
		{
			var options :ActorOptions = new ActorOptions();
			var w :Number = 80 + (500 * Math.random() );
			var h :Number = (50 + (200 * Math.random()));
				
			options.size = new Point( w, 1 );
			options.startPosition = startPosition;
			options.startPosition.x += options.size.x/2 + padding;
			options.startPosition.y = topPadding - options.size.y/2 - h;
			
			options.bodyType = b2Body.KINEMATIC_BODY;
			
			return options;
		}
		
		override protected function scroll():void
		{
			var transformVelocity :b2Vec2 = new b2Vec2( PhiMathUtil.pixelsToMeters( -velocity.x ), 0 );
			
			for each( var actor :IInteractiveActor in actors )
				actor.body.SetLinearVelocity( transformVelocity );
		}
	}
}